'use strict';
const dayjs = require("dayjs");
const {getDefaultModelConfig} = require("../../utils/common");
const {
    formatDate
} = require('../../utils/index.js');
module.exports = app => {
    const { STRING, INTEGER, DATE, TINYINT, TEXT } = app.Sequelize;
    return app.model.define(
        'QualityInspection',
        {
            id: {type: INTEGER, primaryKey: true, autoIncrement: true},
            plan_number: {type: STRING(50), comment: '计划号'},
            license_plate: {type: STRING(20), comment: '车牌号'},
            driver: {type: STRING(100), comment: '驾驶员信息'},
            driver_name: {type: STRING(50), comment: '驾驶员姓名'},
            driver_phone: {type: STRING(20), comment: '驾驶员手机号'},
            material: {type: STRING(100), comment: '销售物料'},
            print_time: {
                type: DATE,
                field: 'print_time',
                comment: '创建时间',
                get() {
                    return formatDate(this.getDataValue('print_time'), 'YYYY-MM-DD HH:mm:ss');
                },
            },
            weigh_time: {
                type: DATE,
                field: 'weigh_time',
                comment: '创建时间',
                get() {
                    return formatDate(this.getDataValue('weigh_time'), 'YYYY-MM-DD HH:mm:ss');
                },
            },
            qrcode: {type: TEXT, comment: '二维码'},
            images: {type: TEXT, comment: '质检单图片，JSON格式存储'},
            status: {type: TINYINT, defaultValue: 1, comment: '状态：1-正常，0-删除'},
            ...getDefaultModelConfig(app)
        },
        {
            tableName: 'quality_inspection',
            timestamps: true,
            createdAt: 'create_time',
            updatedAt: 'update_time'
        }
    );
};
